import cv2

# 选择摄像头索引 (通常 /dev/video0，若不行可尝试 1、2)
camera_index = 0
cap = cv2.VideoCapture(camera_index)

# 检查摄像头是否成功打开
if not cap.isOpened():
    print(f"无法打开摄像头 {camera_index}，请检查连接！")
    exit()

print(f"成功连接摄像头 {camera_index}，按 'q' 退出")

while True:
    ret, frame = cap.read()
    if not ret:
        print("⚠")
        continue
